package ro.gateway.aida.obj;

import java.util.Enumeration;
import java.util.Hashtable;



/**
 * <p>Title: Romanian AIDA</p>
 * <p>Description: :D application</p>
 * <p>Copyright: Copyright (comparator) 2003</p>
 * <p>Company: Romania Development Gateway </p>
 * @author Mihai Popoaei, mihai_popoaei@yahoo.com, smike@intellisource.ro
 * @version 1.0-* @version $Id: AIDAComponent.java,v 1.1 2004/10/24 23:37:10 mihaipostelnicu Exp $
 */
public class AIDAComponent extends AIDAActivityObject
{
      private Hashtable s_names;

      public AIDAComponent()
      {
            this.s_names = new Hashtable();
            this.objectType = TYPE_COMPONENT;
      }

      public void setName( String lang, String name )
      {
            if ( lang == null )
            {
                  return;
            }

            if ( name != null )
            {
                  this.s_names.put( lang, name );
            }
            else
            {
                  this.s_names.remove( lang );
            }
      }

      public String getName( String lang )
      {
            if ( lang == null )
            {
                  return null;
            }

            String result = ( String ) s_names.get( lang );
            if ( result == null )
            {
                  String lng = "ro";
                  if ( s_names.get( lng ) == null )
                  {
                        lng = "en";
                        if ( s_names.get( lng ) == null )
                        {
                              lng = ( String ) s_names.keys().nextElement();
                        }
                  }

                  String desc = ( String ) s_names.get( lng );
                  result = desc + " (" + lng + ")";
            }
            return result;
      }

      public void clearNames()
      {
            this.s_names.clear();
      }

      public String[] getAvailableLanguages()
      {
            if ( s_names.size() < 1 )
                  return null;

            String[] result = new String[ s_names.size() ];
            Enumeration en = s_names.keys();
            int i = 0;
            while ( en.hasMoreElements() )
            {
                  result[ i++ ] = ( String ) en.nextElement();
            }

            return result;
      }

      public boolean equals( AIDAComponent component )
      {
            if ( ( this.id == -1 ) && ( component.id == -1 ) )
            {
                  return false;
            }
            return this.id == component.getId();
      }
}
